package com.android.canvasproject.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.canvasproject.R;
import com.android.canvasproject.model.entity.MenuListItem;

public class MenuListAdapter extends BaseAdapter {

	private Context context;
	private List<MenuListItem> menuItems;

	public MenuListAdapter(Context ctx, List<MenuListItem> drawerItems) {
		context = ctx;
		menuItems = drawerItems;
	}

	@Override
	public int getCount() {
		return menuItems.size();
	}

	@Override
	public Object getItem(int position) {
		return menuItems.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View contentView, ViewGroup parent) {
		if (contentView == null) {
			LayoutInflater inflaterLayout = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			contentView = inflaterLayout.inflate(R.layout.menu_list_item, null);
		}

		ImageView imgIcon = (ImageView) contentView.findViewById(R.id.icon_menu);
		TextView txtTitle = (TextView) contentView.findViewById(R.id.title_menu);
		TextView txtCounter = (TextView) contentView.findViewById(R.id.counter_menu);

		imgIcon.setImageResource(menuItems.get(position).getIcon());
		txtTitle.setText(menuItems.get(position).getTitle());

		if (menuItems.get(position).isCounterVisible())
			txtCounter.setText(menuItems.get(position).getCount());
		else
			txtCounter.setVisibility(View.GONE);

		return contentView;
	}
}